<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminTables extends Migration
{

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin_users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username', 190)
                  ->unique();
            $table->string('password', 60);
            $table->string('name');
            $table->unsignedInteger('role_id');
            $table->string('avatar')
                  ->nullable();
            $table->timestamps();
        });

        Schema::create('admin_roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 50)
                  ->unique();
            $table->timestamps();
        });

        Schema::create('admin_menu', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')
                  ->default(0);
            $table->integer('order')
                  ->default(0);
            $table->string('title', 50);
            $table->string('icon', 50);
            $table->string('uri', 50)
                  ->nullable();

            $table->timestamps();
        });

        Schema::create('admin_role_menu', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('role_id');
            $table->integer('menu_id');
            $table->index(['role_id', 'menu_id']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
        Schema::dropIfExists('admin_roles');
        Schema::dropIfExists('admin_menu');
        Schema::dropIfExists('admin_role_menu');
    }
}
